package com.wephone.Student.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.loopj.android.http.RequestParams;
import com.wephone.Student.R;
import com.wephone.Student.bean.BaseResponse;
import com.wephone.Student.network.HttpClient;
import com.wephone.Student.network.MyResponseHandler;
import com.wephone.Student.util.Constants;

public class ZhidaoAddCommentActivity extends BaseActivity {
	private String qId;
	private String cId;
	private EditText commentEdit;
	
	private MyResponseHandler getHandler(){
		MyResponseHandler handler = new MyResponseHandler(ZhidaoAddCommentActivity.this,BaseResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				if(getDataSuccess){
					Toast.makeText(getApplicationContext(), "评论添加成功", Toast.LENGTH_LONG).show();
					setResult(11);
					finish();
				}
			}
		};
		return handler;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zhidao_add_comment);
		
		init();
	}
	
	private void init(){
		commentEdit = (EditText)findViewById(R.id.add_zhidao_edit);
		
		findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		findViewById(R.id.btn_top_right).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if(commentEdit.getText().toString().trim().replace("\n", "").length()>0){
//					System.out.println("-----qId-----"+qId);
//					System.out.println("-----cId-----"+cId);
//					System.out.println("-----uid-----"+BaseActivity.getMyInfo(getApplicationContext()).getuId());
					RequestParams params = new RequestParams();
					params.put("id", qId);
					params.put("replyid", cId);
					params.put("uid", BaseActivity.getMyInfo(getApplicationContext()).getuId());
					params.put("content", commentEdit.getText().toString());
					params.put("anonymous", "0");
					HttpClient.getInstance().post(Constants.API_ADD_ZHIDAO_ASK_REPLY_URL, params, getHandler());
					
					Toast.makeText(getApplicationContext(), "发布中", Toast.LENGTH_SHORT).show();
				}else{
					Toast.makeText(getApplicationContext(), "评论内容必须填写", Toast.LENGTH_LONG).show();
				}
			}
		});
		
		Bundle bundle = getIntent().getExtras();
		if(bundle!=null){
			qId = bundle.getString("qId");
			cId = bundle.getString("cId");
		}
	}

}
